import express from 'express';
import { upload, handleUploadError } from '../common/upload.js';
import Result from '../common/result.js';

const router = express.Router();

// 通用文件上传接口
router.post('/upload', 
  upload.single('file'),
  handleUploadError,
  (req, res) => {
    if (!req.file) {
      return Result.error(res, 'No file uploaded');
    }
    // 返回文件访问路径，使用相对路径
    const fileUrl = `/uploads/${req.file.filename}`;
    return Result.success(res, { url: fileUrl });
  }
);

export default router; 